//
//  LeftDrawerVC.m
//  AKPZ
//
//  Created by Lexi on 16-3-15.
//  Copyright (c) 2016年 aikangpeizhen. All rights reserved.
//

#import "LeftDrawerVC.h"

@interface LeftDrawerVC ()

@property (assign, nonatomic) LeftDrawerButton selectedBtnTag;
@property (weak, nonatomic) IBOutlet UILabel *usernameLabel;
@property (weak, nonatomic) IBOutlet UIButton *logoutBtn;
@property (weak, nonatomic) IBOutlet UIButton *indexBtn;
@property (weak, nonatomic) IBOutlet UIButton *helpBtn;
@property (weak, nonatomic) IBOutlet UIButton *checkNewBtn;
@property (weak, nonatomic) IBOutlet UIButton *aboutUsBtn;

@end

@implementation LeftDrawerVC

@synthesize delegate;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    //登录成功逻辑处理
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserLoginSuccess) name:UserLoginNotification object:nil];
    //退出登录逻辑处理
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onUserLogoutSuccess) name:UserLogoutNotification object:nil];
    _logoutBtn.exclusiveTouch = YES;
    _helpBtn.exclusiveTouch = YES;
    _checkNewBtn.exclusiveTouch = YES;
    _aboutUsBtn.exclusiveTouch = YES;
    _indexBtn.exclusiveTouch = YES;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
}

- (void)onUserLoginSuccess {
    _usernameLabel.text = @"龙城狂霸拽少";
}

- (void)onUserLogoutSuccess {
    
}

- (void)setSelectedBtnTag:(LeftDrawerButton)selectedBtnTag {
    UIButton *oldBtn = (UIButton *)[self.view viewWithTag:_selectedBtnTag];
    if ([oldBtn isKindOfClass:[UIButton class]]) {
        oldBtn.selected = NO;
    }
    _selectedBtnTag = selectedBtnTag;
    UIButton *btn = (UIButton *)[self.view viewWithTag:_selectedBtnTag];
    if (_selectedBtnTag == LeftDrawerButton_CheckNew) {
        return;
    }
    if (_selectedBtnTag == LeftDrawerButton_Logout) {
        return;
    }
    btn.selected = YES;
}

- (IBAction)leftDrawerBtnClicked:(id)sender {
    UIButton *button = (UIButton *)sender;
    LeftDrawerButton btnType = LeftDrawerButton_Login;
    if ([button isEqual:_logoutBtn]) {
        btnType = LeftDrawerButton_Logout;
    }
    else if ([button isEqual:_indexBtn]) {
        btnType = LeftDrawerButton_Index;
    }
    else if ([button isEqual:_helpBtn]) {
        btnType = LeftDrawerButton_Help;
    }
    else if ([button isEqual:_checkNewBtn]) {
        btnType = LeftDrawerButton_CheckNew;
    }
    else if ([button isEqual:_aboutUsBtn]) {
        btnType = LeftDrawerButton_AboutUs;
    }
    
    self.selectedBtnTag = btnType;
    
    if ([delegate respondsToSelector:@selector(leftSideDrawerViewDelegate:)]) {
        [delegate leftSideDrawerViewDelegate:btnType];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

@end
